//
//  YCBarItem.swift
//  weiBoSwift
//
//  Created by 刘胤辰 on 16/7/19.
//  Copyright © 2016年 it.com. All rights reserved.
//

import UIKit

class YCBarItem: UIBarButtonItem {
    
    init(title: String?,imageName:String?, target:AnyObject? , action: Selector) {
        super.init()
        
        let btn = UIButton()
        
        //当有文字没有图片的时候
        if let title=title {
            
            btn.setTitle(title, forState: UIControlState.Normal)
            btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
            btn.titleLabel?.font=UIFont.systemFontOfSize(16)
        }
        
        //当有图片没有文字的时候
        if let imageName=imageName {
            
            btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        }
        
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        btn.sizeToFit()
        
        self.customView=btn
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
